package com.zbhk.qc.controller;

import com.zbhk.qc.dto.ResultVO;
import com.zbhk.qc.dto.UserAddVO;
import com.zbhk.qc.entity.VdUser;
import com.zbhk.qc.service.UserServer;
import com.zbhk.qc.util.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController("UserController")
@RequestMapping(value = "/user")
@RequiredArgsConstructor
@Api(tags = "用户相关接口")
public class UserController {

    @Autowired
    private UserServer userServer;

    @ApiOperation(value = "注册，新增用户",notes = "新增")
    @PostMapping("/addUser")
    public ResultVO addUser(@RequestBody UserAddVO userAddVO){
        VdUser vdUser = new VdUser();
        try {
            vdUser = userServer.addUser(userAddVO);
        }catch (Exception e){
            return ResultVOUtil.error(e.getMessage());
        }
        return  ResultVOUtil.success(vdUser);
    }

    @ApiOperation(value = "查看用户上下级关系详情", notes = "", produces = "application/json")
    @GetMapping("getUpDownDetail")
    public ResultVO getUpDownDetail(@ApiParam(value = "用户主键id") @RequestParam(required = true) Long id) throws Exception {
        Map<String,Object> map = new HashMap<>();
        try {
            map = userServer.getUpDownDetail(id);
        }catch (Exception e){
            return ResultVOUtil.error(e.getMessage());
        }
        return  ResultVOUtil.success(map);
    }

    /*@Autowired
    private UserServer userServer;

    @GetMapping("/getUserList")
    @ApiOperation(value = "查询员工数据", notes = "查询员工分页数据")
    public IPage<UserListResponseVO> getUserList(
            @ApiParam(value = "员工工号") @RequestParam(required = false) String usercode,
            @ApiParam(value = "员工名称") @RequestParam(required = false) String usernamecn,
            @ApiParam(value = "用户名称") @RequestParam(required = false) String departmentcode,
            @ApiParam(value = "页数") @RequestParam(required = true ,defaultValue = "10") Integer pageSize,
            @ApiParam(value = "页码") @RequestParam(required = true,defaultValue = "1") Integer pageNumber) {
        IPage<UserListResponseVO> list = null;
        try {
            list = userServer.getUserList(usercode,usernamecn,departmentcode,pageSize,pageNumber);
        }catch (Exception e) {
            return list;
        }
        return list;
    }

    @ApiOperation(value = "新增用户", notes = "", produces = "application/json")
    @PostMapping("save")
    public Object save(@Valid @ModelAttribute SysUserVO sysUserVO) throws Exception {
        return   userServer.save(sysUserVO);
    }

    @ApiOperation(value = "修改用户", notes = "", produces = "application/json")
    @PostMapping("update")
    public Object update(@Valid @ModelAttribute SysUserVO sysUserVO) throws Exception {
        return   userServer.update(sysUserVO);
    }

    @ApiOperation(value = "删除用户", notes = "", produces = "application/json")
    @GetMapping("delete")
    public Object delete(@ApiParam(value = "用户编号") @RequestParam(required = true) String usercode) throws Exception {
        return   userServer.delete(usercode);
    }

    @ApiOperation(value = "查看用户", notes = "", produces = "application/json")
    @GetMapping("get")
    public Object get(@ApiParam(value = "用户编号") @RequestParam(required = true) String usercode) throws Exception {
        return   userServer.get(usercode);
    }*/


}
